package com.frcdi.qms.web.controller.masterdata;

import com.frcdi.qms.common.core.controller.BaseController;
import com.frcdi.qms.common.core.domain.AjaxResult;
import com.frcdi.qms.common.core.page.TableDataInfo;
import com.frcdi.qms.common.utils.poi.ExcelUtil;
import com.frcdi.qms.masterdata.domain.MethodProject;
import com.frcdi.qms.masterdata.service.IMethodProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 方法--项目Controller
 *
 * @author cell
 * @date 2023-10-16
 */
@Api(tags = "方法--项目")
@RestController
@RequestMapping("/masterData/methodProject")
public class MethodProjectController extends BaseController
{
    @Autowired
    private IMethodProjectService methodProjectService;

    /**
     * 查询方法--项目列表
     */
    @ApiOperation("查询方法--项目列表")
    @PreAuthorize("@ss.hasPermi('masterData:method:edit')")
    @GetMapping("/list")
    public TableDataInfo list(MethodProject methodProject)
    {
        startPage();
        List<MethodProject> list = methodProjectService.selectMethodProjectList(methodProject);
        return getDataTable(list);
    }

    /**
     * 导出方法--项目列表
     */
    @ApiOperation("导出方法--项目列表")
    @PreAuthorize("@ss.hasPermi('masterData:method:edit')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, MethodProject methodProject)
    {
        List<MethodProject> list = methodProjectService.selectMethodProjectList(methodProject);
        ExcelUtil<MethodProject> util = new ExcelUtil<MethodProject>(MethodProject.class);
        util.exportExcel(response, list, "方法--项目数据");
    }

    /**
     * 获取方法--项目详细信息
     */
    @ApiOperation("获取方法--项目详细信息")
    @PreAuthorize("@ss.hasPermi('masterData:method:edit')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(methodProjectService.selectMethodProjectById(id));
    }

    /**
     * 新增方法--项目
     */
    @ApiOperation("新增方法--项目")
    @PreAuthorize("@ss.hasPermi('masterData:method:edit')")
    @PostMapping
    public AjaxResult add(@RequestBody MethodProject methodProject)
    {
        if (methodProjectService.selectMethodProjectList(methodProject).size()>0){
            return error("已存在!");
        }
        return toAjax(methodProjectService.insertMethodProject(methodProject));
    }

    /**
     * 修改方法--项目
     */
    @ApiOperation("修改方法--项目")
    @PreAuthorize("@ss.hasPermi('masterData:method:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody MethodProject methodProject)
    {
        return toAjax(methodProjectService.updateMethodProject(methodProject));
    }

    /**
     * 删除方法--项目
     */
    @ApiOperation("删除方法--项目")
    @PreAuthorize("@ss.hasPermi('masterData:method:edit')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(methodProjectService.deleteMethodProjectByIds(ids));
    }
}
